package com.lzx.demo.bloodpressurehelper;

import android.app.FragmentManager;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.view.Gravity;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.lzx.demo.bloodpressurehelper.db.MyDBOpenHelper;
import com.lzx.demo.bloodpressurehelper.fragment.home.MyHomeFragmentPageAdapter;


public class MainActivity extends FragmentActivity {

    private RadioGroup ly_tab_bar;
    private FrameLayout ly_content;
    private ViewPager vpager;
    private MyHomeFragmentPageAdapter mfragment;
    private DrawerLayout dLayout;
    //底部导航按钮
    private RadioButton rb_channel;
    private RadioButton rb_message;
    private RadioButton rb_better;

    //数据库部分
    private MyDBOpenHelper mDBOpenHelper;
    private Context mContext;
    private SQLiteDatabase db;


    private FragmentManager mfragmentManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        /*
          创建数据表
         */
        initDB();

        initViews();
    }

    public void initDB(){
        mContext = MainActivity.this;
        mDBOpenHelper = new MyDBOpenHelper(mContext,"APPDB.db",null,1);
        db = mDBOpenHelper.getWritableDatabase();
    }

    private void initViews(){

        ly_tab_bar = (RadioGroup) findViewById(R.id.ly_tab_bar);
        dLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        dLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.RIGHT);

        vpager = (ViewPager) findViewById(R.id.vpager);
        mfragmentManager = getFragmentManager();
        mfragment = new MyHomeFragmentPageAdapter(getSupportFragmentManager());
        vpager.setAdapter(mfragment);
        vpager.setCurrentItem(0);
    }

    /**
     * 获取SQLite数据库对象
     * @return
     */
    public SQLiteDatabase getDb() {
        return db;
    }

    /**
     * DBOpenHelper
     * @return
     */
    public MyDBOpenHelper getmDBOpenHelper() {
        return mDBOpenHelper;
    }

}
